package com.bbc.core.constants;

import com.bbc.core.assertion.CommonExceptionAssert;
import com.bbc.core.exception.BaseException;
import com.bbc.core.model.R;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum CommonResponseCode implements CommonExceptionAssert {
   SUCCESS(200, "SUCCESS"),
   SERVER_BUSY(9998, "服务器繁忙"),
   SERVER_ERROR(9999, "网络异常"),
   DATE_NOT_NULL(5001, "日期不能为空"),
   DATETIME_NOT_NULL(5001, "时间不能为空"),
   TIME_NOT_NULL(5001, "时间不能为空"),
   DATE_PATTERN_MISMATCH(5002, "日期[%s]与格式[%s]不匹配，无法解析"),
   PATTERN_NOT_NULL(5003, "日期格式不能为空"),
   PATTERN_INVALID(5003, "日期格式[%s]无法识别");

   private int code;
   private String message;

   public static void assertSuccess(R r) {
      SERVER_ERROR.assertNotNull(r);
      int code = r.getCode();
      if (SUCCESS.getCode() != code) {
         String msg = r.getMsg();
         throw new BaseException(code, msg);
      }
   }

   // $FF: synthetic method
   private static CommonResponseCode[] $values() {
      return new CommonResponseCode[]{SUCCESS, SERVER_BUSY, SERVER_ERROR, DATE_NOT_NULL, DATETIME_NOT_NULL, TIME_NOT_NULL, DATE_PATTERN_MISMATCH, PATTERN_NOT_NULL, PATTERN_INVALID};
   }

}
